package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.SpareSearchBean;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

/**
 * 服务商  备件查询
 * <p>
 * Created by Administrator on 2017/9/13.
 */

public class SpareSelectAdapter extends BaseRecyclerViewAdapter<SpareSearchBean.Rows> {

    public SpareSelectAdapter(Context context) {
        super(context);
    }

    @Override
    public ServiceSpareInquireViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_search_spare, null);
        return new ServiceSpareInquireViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {
        ServiceSpareInquireViewHolder holder = (ServiceSpareInquireViewHolder) rholder;

        final SpareSearchBean.Rows rows = getItem(position);
        holder.tvName.setText(rows.getAssetName());
        holder.tvModel.setText(TextUtils.isEmpty(rows.getAssetSerial()) ? "" : rows.getAssetSerial());
//        holder.tvBrands.setText(TextUtils.isEmpty(rows.getBrandFirm()) ? "" : rows.getBrandFirm() + "/");
//        holder.tvObjectModel.setText(rows.getObjectModel());
        //状态0-正常，1-待检测，2-维修，3-借出，4报废，5-闲置
        if ("0".equals(rows.getCurStatus())) {
            holder.tvStatus.setText("正常");
            holder.tvStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_3bbe7c));
        } else if ("1".equals(rows.getCurStatus())) {
            holder.tvStatus.setText("待检测");
            holder.tvStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_e64545));
        } else if ("2".equals(rows.getCurStatus())) {
            holder.tvStatus.setText("维修");
            holder.tvStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_e9981f));
        } else if ("3".equals(rows.getCurStatus())) {
            holder.tvStatus.setText("借出");
            holder.tvStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_e9981f));
        } else if ("4".equals(rows.getCurStatus())) {
            holder.tvStatus.setText("报废");
            holder.tvStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_e64545));
        } else if ("5".equals(rows.getCurStatus())) {
            holder.tvStatus.setText("闲置");
            holder.tvStatus.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_e9981f));
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v, position);
            }
        });
    }

    static class ServiceSpareInquireViewHolder extends RecyclerView.ViewHolder {

        private View itemView;
        private TextView tvName;//名称
        private TextView tvModel;//序列号
        private TextView tvObjectModel;//对象型号
        private TextView tvBrands;
        private TextView tvStatus;//状态

        public ServiceSpareInquireViewHolder(View view) {
            super(view);
            itemView = view;
            tvName = itemView.findViewById(R.id.tv_name);
            tvModel = itemView.findViewById(R.id.tv_model);
            tvBrands = itemView.findViewById(R.id.tv_brands);
            tvObjectModel = itemView.findViewById(R.id.tv_object_model);
            tvStatus = itemView.findViewById(R.id.tv_status);
        }
    }
}
